name: langkit-ci

on:
  pull_request:
  push:
    branches: [main]
    tags:
      - "[0-9]+.[0-9]+.[0-9]+*"

jobs:
  python-ci:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macOS-latest, windows-latest]
        python-version: ["3.8", "3.9", "3.10", "3.11"]

    steps:
      - uses: actions/checkout@v3
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        id: setup-python
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install Poetry
        uses: abatilo/actions-poetry@v2.0.0
        with:
          poetry-version: 1.5.1
      - uses: actions/cache@v3
        id: poetry-cache
        name: Cache dependencies based on poetry.lock file
        with:
          path: ./.venv
          key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-all-${{ hashFiles('**/poetry.lock') }}
      - name: check poetry env
        run: poetry env info
      - name: Install dependencies
        if: steps.poetry-cache.outputs.cache-hit != 'true'
        run: make install
      - name: Log cache hit
        if: steps.poetry-cache.outputs.cache-hit == 'true'
        run: echo 'poetry cache hit, skipping poetry install'
      - name: Configure whylogs
        run: mkdir ~/.whylogs && echo \"\" >> ~/.whylogs/disable_telemetry
      - name: Run pre-commit checks
        if: ${{ matrix.python-version == 3.8 && matrix.os == 'ubuntu-latest' }}
        run: poetry run pre-commit run --all-files
      - name: Run build
        run: poetry build
      - name: Run test
        run: poetry run pytest
